package script;

import domain.User;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

import java.util.Date;

public class SafeExprSample {

    public static void main(String[] args) {

        User user = new User();
        user.setName("chengxq");
        user.setLastVist(new Date());
        user.setPlaceOfBrith("ZS");


        ExpressionParser parser = new SpelExpressionParser();
        StandardEvaluationContext context = new StandardEvaluationContext(user);
        String city = parser.parseExpression("PlaceOfBrith").getValue(context, String.class);
        System.out.println(city);

        user.setPlaceOfBrith(null);
        city = parser.parseExpression("PlaceOfBrith").getValue(context, String.class);
        System.out.println(city);


    }

}
